<template>
	<jk-dialog
		v-model="showDialog"
		title="停机明细"
		width="1000px"
		:show-content-loading="showLoading"
		append-to-body
		:show-close-btn="true"
		:show-confirm-btn="false"
		:show-cancel-btn="false"
		@on-close="onVisibleChange(false)"
		@on-visible-change="onVisibleChange"
	>
		<div ref="box1" class="header-bar">
			<el-button class="margin-bottom-20" type="primary" icon="el-icon-files">机台: <span class="title-val">{{ dataItem.name }}</span></el-button>
			<div class="flex-center">
				<div class="item-gap"><el-button size="mini" icon="el-icon-odometer">停机次数: <span class="title-val">31</span></el-button></div>
				<el-button size="mini" icon="el-icon-time">停机时长: <span class="title-val">222</span></el-button>
			</div>
		</div>
		<jk-table :span-method="mergeColMethod" border :data="tableData" :height="dialogTableHeight - 20">
			<vxe-column title="停机类型" align="center" field="typeName" :min-width="100"></vxe-column>
			<vxe-column title="停机开始时间" align="center" field="subTitle" :min-width="100"></vxe-column>
			<vxe-column title="停机结束时间" align="center" field="subTitle" :min-width="100"></vxe-column>
			<vxe-column title="停机时长" align="center" field="subTitle" :min-width="100"></vxe-column>
			<vxe-column title="停机时表数" align="center" field="subTitle" :min-width="100"></vxe-column>
			<vxe-column title="在产品种" align="center" field="subTitle" :min-width="100"></vxe-column>
			<vxe-column title="在产批号" align="center" field="subTitle" :min-width="100"></vxe-column>
			<vxe-column title="通知单号" align="center" field="subTitle" :min-width="100"></vxe-column>
			<!--<vxe-column title="停机开始时间" align="left" field="productUseCommunicationItemList" :min-width="100">
				<template slot-scope="scope">

				</template>
			</vxe-column>-->
		</jk-table>
	</jk-dialog>
</template>

<script>
    import calHeight from '/src/mixins/cal-dialog-height';
    import { productionProductUseCommunicationGet } from '../../../api/production/csUseMaterialStatistics';
    export default {
        name: 'CsUseMaterialStatistics',
        props: {
            dialogState: {
                type: Boolean,
                default: false
            },
            dataItem: {
                type: Object,
                default() {
                    return {};
                }
            }
        },
        mixins: [calHeight],
        data() {
            return {
                showDialog: false,
                showLoading: false,
                ruleForm: {},
                tableData: [
                    { typeName: '翻改停机' },
                    { typeName: '翻改停机' },
                    { typeName: '落纱停机' },
                    { typeName: '落纱停机' },
                    { typeName: '保养停机' },
                    { typeName: '保养停机' },
                    { typeName: '保养停机' },
                    { typeName: '其他停机' },
                    { typeName: '其他停机' }
                ]
            };
        },
        methods: {
            mergeColMethod({ row, _rowIndex, column, visibleData }) {
                const prevRow = visibleData[_rowIndex - 1];
                let nextRow = visibleData[_rowIndex + 1];
                if (column.property === 'typeName') {
                    if (prevRow && prevRow.typeName === row.typeName) {
                        return { rowspan: 0, colspan: 0 };
                    } else {
                        let countRowspan = 1;
                        while (nextRow && nextRow.typeName === row.typeName) {
                            nextRow = visibleData[++countRowspan + _rowIndex];
                        }
                        if (countRowspan > 1) {
                            return { rowspan: countRowspan, colspan: 1 };
                        }
                    }
                }
            },
            onVisibleChange(e) {
                this.$emit('on-visible-change', e);
                if (!e) {
                    Object.assign(this.$data, this.$options.data());
                    this.$nextTick(() => {
                        this.$refs.ruleForm.resetFields();
                    });
                }
            },
            getDetailRequest() {
                this.showLoading = true;
                return productionProductUseCommunicationGet({ id: this.dataId }).then(res => {
                    this.showLoading = false;
                    if (res.data.status === 200) {
                        this.ruleForm = res.data.res;
                    }
                });
            }
        },
        watch: {
            dialogState(newVal) {
                this.showDialog = newVal;
                if (newVal) {
                    // this.getDetailRequest();
                }
            }
        }
    };
</script>
<style scoped lang="scss">
    .header-bar {
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        margin-bottom: 10px;
        .title-val {
            font-weight: 700;
        }
    }
</style>
